package com.xq.shop.controller;


import com.xq.shop.dto.EditExchangeRateDto;
import com.xq.shop.dto.QueryDto;
import com.xq.shop.service.IExchangeRateService;
import com.xq.shop.service.IUserService;
import com.xq.shop.vo.ExchangeRateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import utils.BasePage;
import utils.BaseResult;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 汇率表 前端控制器
 * </p>
 *
 * @author gaoxiaojin
 * @since 2024-07-16
 */
@RestController
@RequestMapping("/exchange/rate")
public class ExchangeRateController {

    private final IExchangeRateService exchangeRateService;
    private final IUserService userService;

    @Autowired
    public ExchangeRateController(IExchangeRateService exchangeRateService, IUserService userService) {
        this.exchangeRateService = exchangeRateService;
        this.userService = userService;
    }

    @RequestMapping("/page")
    public BaseResult<BasePage<ExchangeRateVo>> query(@RequestBody QueryDto dto, HttpServletRequest request) {
        userService.getInfo(request);
        BaseResult<BasePage<ExchangeRateVo>> result = new BaseResult<>();
        BasePage<ExchangeRateVo> page = exchangeRateService.pageQuery(dto);
        result.initializeSuccess(page);
        return result;
    }

    @RequestMapping("/edit")
    public BaseResult<Void> query(@RequestBody EditExchangeRateDto dto, HttpServletRequest request) {
        userService.getInfo(request);
        BaseResult<Void> result = new BaseResult<>();
        exchangeRateService.edit(dto);
        result.initializeSuccess();
        return result;
    }

}
